package agents;

import extra.Position;
import game.constants.ReferenceAgent;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.Agent;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionModifySpetialFeature;
import constants.Constants;



public class AgentSearchTargetToAttack extends Agent{

	SpetialFeature objectIdToAttack;
	SpetialFeature objectIdToFollow;
	SpetialFeature visionRagne;
	
	ActionModifySpetialFeature actionModifyTargetToAttack;
	ActionModifySpetialFeature actionModifyTargetToFollow;
	
	int cont =0;

	@Override
	public void initializeActionList() {
		actionModifyTargetToAttack= new ActionModifySpetialFeature();
		listActions.add(actionModifyTargetToAttack);
		
		actionModifyTargetToFollow= new ActionModifySpetialFeature();
		listActions.add(actionModifyTargetToFollow);

	}

	@Override
	public void initializeSpecialFeatures() {
		
		objectIdToAttack= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_TARGET_ID_TO_ATTACK);
		addSpetialFeature(objectIdToAttack);
		
		visionRagne = new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_VISION_RANGE);
		addSpetialFeature(visionRagne);
		
	}

	@Override
	public void initializeName() {
		name="Agent Search Attack Object";
		
	}

	@Override
	public void initializeId() {
		this.id=ReferenceAgent.AGENT_SEARCH_TARGET_TO_ATTACK;
		
	}

	@Override
	public void updateChild(WorldObject object, Universe universe, double time) {

		if (objectIdToAttack.getValue()!=Constants.NO_OBJECT_ID){
			return;
		}
		
		for(WorldObject objToAttack : universe.getListObjects()){
			
			if(objToAttack.getOwner()==Constants.NO_OWNER || objToAttack.getOwner()==object.getOwner()){
				continue;
			}
			double distance = Position.DistanceBetween(object.getPosition(), objToAttack.getPosition());
			
			if(distance<visionRagne.getValue()){
				/*actionModifyTargetToFollow.setSource(object);
				actionModifyTargetToFollow.setTarget(object);
				actionModifyTargetToFollow.setFeatureId(ReferenceSpecialFeature.SPETIAL_FEATURE_TARGET_ID_TO_FOLLOW);
				actionModifyTargetToFollow.setValue(objectToAttack.getObjectId());
				universe.setAction(actionModifyTargetToFollow);*/
		
				actionModifyTargetToAttack.setSource(object);
				actionModifyTargetToAttack.setTarget(object);
				actionModifyTargetToAttack.setFeatureId(ReferenceSpecialFeature.SPETIAL_FEATURE_TARGET_ID_TO_ATTACK);
				actionModifyTargetToAttack.setValue(objToAttack.getID());				
				universe.setAction(actionModifyTargetToAttack);
			}
		}
	}

	

}
